package com.guoxin.chapter1;

import java.util.Random;
import java.util.concurrent.TimeUnit;

/**
 * @author guoxin
 * @date 2019/8/8
 */
public class RandomlyThread {
    private static final Random RANDOM = new Random();

    public static void main(String[] args) throws InterruptedException {
        new Thread(new MyThread()).start();
        for (int i = 0; i < 10; i++) {
            int time = RANDOM.nextInt(1000);
            TimeUnit.MILLISECONDS.sleep(time);
            System.out.println("run= " + Thread.currentThread().getName());
        }
    }

    private static class MyThread implements Runnable {
        @Override
        public void run() {
            try {
                for (int i = 0; i < 10; i++) {
                    int time = RANDOM.nextInt(1000);
                    TimeUnit.MILLISECONDS.sleep(time);
                    System.out.println("run= " + Thread.currentThread().getName());
                }
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
